const std = @import("std");
const uv = @import("uv.zig");

const Context = struct {
    count: u64 = 0,
};

const Timer = uv.TimerTyped(Context);

fn counter(timer: *Timer) void {
    const ctx = timer.getData().?;

    std.debug.print("counter: {d}\n", .{ctx.count});

    ctx.count += 1;
    if (ctx.count >= 10) {
        timer.stop();
        timer.close(null);
    }
}

pub fn main() !void {
    const loop = uv.Loop.default();
    defer loop.deinit();

    var timer = Timer{};
    try timer.init(loop);

    var ctx = Context{};
    timer.setData(&ctx);

    try timer.start(counter, 0, 100);

    try loop.run(.default);
}
